<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>微信支付</title>
    <script src="__JS__/jquery2.1.1.min.js"></script>
    <script src="__JS__/layer.min.js"></script>
    <script src="__JS__/layer1.7/layer.js"></script>
</head>

<body>
<script>
    var type="{$type}";
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', jsApiCall);
            document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
        }
    }
    $(function(){
        jsApiCall();
    });

    function redirect(){
        location.href = "{:U('Wx/Orders/orders')}";
    }

    function jsApiCall()
    {
        WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                {$jsApiParameters},
                function(res){
                    WeixinJSBridge.log(res.err_msg);
                    reg=/cancel/i;
                    ok=/ok/i;
                    if(reg.test(res.err_msg)){
                        layer.msg('付款取消');
                        location.href="/Wap/User/member";
                    }else if(res.err_msg == "get_brand_wcpay_request:ok") {
                        if($type==2){
                            //充值
                            location.href="/Wap/User/member";
                        }else{
                            location.href="/Wap/Orders/index";
                            //订单
                        }
                    }else {
                        alert(res.err_code+res.err_desc+res.err_msg);
                    }
                    //alert("{$jsApiParameters}");
                }
        );
    }
</script>


</body>

</html>
